/**
 * 分配弹框
 */
import React, { Component } from 'react';
import { Modal, message } from 'antd';
import { styles } from '../../../components/filter';
import Table from './table';
import Filter from './filter';

class Operator extends Component {
	state = {
		queryData: null,
		selectedRows: []
	}

	onOk = () => {
		const { onOk } = this.props;
		const { selectedRows } = this.state;
		if (selectedRows.length) {
			onOk(selectedRows[0]);
		} else {
			message.warning('请选择一个供应商');
		}
	}

	render() {
		const { queryData, selectedRows } = this.state;
		const { visible, ...props } = this.props;
		return (
			<Modal {...props} visible={visible} onOk={this.onOk}>
				<Filter onChange={data => this.setState({ queryData: data })} visible={visible} />
				<Table
					queryData={queryData}
					rowSelection={{
						type: 'radio',
						onChange: (key, rows) => this.setState({ selectedRows: rows }),
						selectedRowKeys: selectedRows.map(r => r.id)
					}}
					rowKey="id"
				/>
			</Modal>
		);
	}
}

export default Operator;
